
<div id="list">
  <h2>Listing Applications</h2>
  <?r if @applications.nil? or @applications.empty? ?>
      
  <?r else ?>
    <table>
      <tr>
        <th>Name</th>
        <th>Version</th>
        <th>State</th>
        <th>Operation</th>
      </tr>
      <?r @applications.each do |app| ?>
      <tr>
        <?r if app.pid ?>
          <td>
            <a href='http://localhost:#{h app.port}' target='_blank'>#{h app.name}</a>
          </td>
          <td>
            #{h app.version}
          </td>
          <td>
            ON / #{Applications.a("OFF", :stop, app.id)}
          </td>
        <?r else ?>
          <td>
            #{h app.name}
          </td>
          <td>
            #{h app.version}
          </td>
          <td>
            <a href='#{Applications.r(:start, app.id)}' target='_blank' onclick='setTimeout(function(){window.location = window.location;}, 1000)'>
              ON</a> / OFF
          </td>
        <?r end ?>
          <td id="uninstall-#{h app.name}-#{h app.version}">
            #{Applications.a("-", :uninstall, app.id)}
          </td>
      </tr>
      <?r end ?>
    </table>
  <?r end ?>
</div>
<div id="new">
  <h2>Installing Applications</h2>
  <form action="#{Applications.r(:install)}" method="POST" enctype="multipart/form-data">
    <input type="radio" name="by" value="name" id="by_name_button" checked>
    <label for="by_name_button">by name</label>
    <input type="radio" name="by" value="file" id="by_file_button">
    <label for="by_file_button">by file</label>

    <div id="by_name">
      <input type="text" name="name" size="30">
      <input type="submit" value="install">
    </div>

    <div id="by_file" style="display: none;">
      <input type="file" name="gem" size="50">
      <input type="submit" value="install">
    </div>
  </form>
</div>

<script type="text/javascript">
$(function(){
  $("#by_name_button").click(function(){
    $("#by_name").show();
    $("#by_file").hide();
    return true;
  });
  $("#by_file_button").click(function(){
    $("#by_name").hide();
    $("#by_file").show();
    return true;
  });
});
</script>
